-4

When I call the Ghash function, I get a promise I need to receive the result of this promise which is a hash, without that hash I cannot get the image I am looking for

async function Ghash(name){
    let res = await fetch(`https://account.imperiomc.click/${name}.json?`+new Date().getTime()), json = await res.json(), hash, skin;
    if (json.skins.slim != null){
        hash = await json.skins.slim
        skin = "Alex"
    } else {
        hash = await json.skins.default
        skin = "Steve"
    }
    console.log("Skin model is "+skin)
    return hash
}
function populateAuthAccounts(){
    const authAccounts = ConfigManager.getAuthAccounts()
    const authKeys = Object.keys(authAccounts)
    if(authKeys.length === 0){
        return
    }
    const selectedUUID = ConfigManager.getSelectedAccount().uuid

    let authAccountStr = ''
    authKeys.map((val) => {
        const acc = authAccounts[val]
        const hash = Ghash(acc.displayName)
        const settingsCurrentAccounts = document.getElementById('settingsCurrentAccounts')
            let url = `https://account.imperiomc.click/preview/hash/${hash}?`+new Date().getTime();
            authAccountStr += `<div class="settingsAuthAccount" uuid="${acc.uuid}">
                <div class="settingsAuthAccountLeft">
                    <img class="settingsAuthAccountImage" alt="${acc.displayName}" src="${url}">
                </div>
                <div class="settingsAuthAccountRight">
                    <div class="settingsAuthAccountDetails">
                        <div class="settingsAuthAccountDetailPane">
                            <div class="settingsAuthAccountDetailTitle">Usuario</div>
                            <div class="settingsAuthAccountDetailValue">${acc.displayName}</div>
                        </div>
                        <div class="settingsAuthAccountDetailPane">
                            <div class="settingsAuthAccountDetailTitle">UUID</div>
                            <div class="settingsAuthAccountDetailValue">${acc.uuid}</div>
                        </div>
                    </div>
                    <div class="settingsAuthAccountActions">
                        <button class="settingsAuthAccountSelect" ${selectedUUID === acc.uuid ? 'selected>Selected Account &#10004;' : '>Selecciona una cuenta'}</button>
                        <div class="settingsAuthAccountWrapper">
                            <button class="settingsAuthAccountLogOut">Cerrar sesión</button>
                        </div>
                    </div>
                </div>
            </div>`
            settingsCurrentAccounts.innerHTML = authAccountStr  
    })
}

if I put all the content of authKeys.map((val) inside .then, for example (click me) the functions doesnt work with the buttons but the hash gives me the result I am looking for

i need to export the Ghash to hash (without any .then or async the code) that this is not related to Why is [...] instead of a value? if i do that, i have new issue, see the "if I put [...] inside .then..." moderators (dont close)

if anyone can tellme how i can fix it... I would be very grateful to you

  • 1
    You need to explain the problems better. – epascarello Mar 05 '22 at 15:55
  • I have changed the way I have expressed myself, I hope to explain myself better – Alex Gonzalez Mar 05 '22 at 21:11
  • in case you want your buttons to do anything you should set any eventListener to them, which fires anything when e.g. got clicked. I can't see any Listener targeting your buttons. by the way you should target them after you did create them within your js – VebDav Mar 05 '22 at 21:16

1 Answers1

0

Maybe you should put await, because the Gash function is asynchronous, you need to wait for the response.

const hash = await Ghash(acc.displayName)
Asiel Alonso
  • 561
  • 4
  • 6