Аутентификация с помощью Waveskeeper: как исправить «Волны не определены» - PullRequest
2 голосов
/ 24 мая 2019

Я пытаюсь создать страницу, которая аутентифицирует пользователя с помощью Waveskeeper. Я установил аддон wavekeeper на Chrome, но получаю сообщение об ошибке: ReferenceError: Волны не определены

Пробовал хром и храбрый, та же ошибка.


    $(document).ready ( function () 
    {

        /*
        if(typeof Waves !== 'undefined'){
            alert("Waves Keeper not installed or loaded.");
            console.log('installed')
        }else{
            alert("Waves Keeper not installed or loaded.");
            console.log('not installed')
            return
        }
        */
        console.log('Start');
        console.log(Waves);
        WavesKeeper.initialPromise
        .then((keeperApi) => { 
            /*...init app*/        
            console.log(WavesKeeper);
            keeperApi.publicState().then( state => startApp(state));
        })

        function startApp(state)
        {

            $('#address').text(state.account.address);
            $('#balance').text(state.account.balance.available*1e-8);
            $('#network').text(state.network.code);
        }
    ```

I am receiving this error:

jquery-3.4.0.min.js:2 jQuery.Deferred exception: Waves is not defined ReferenceError: Waves is not defined
    at HTMLDocument.<anonymous> (http://localhost/test/wk.html:20:17)
    at e (https://code.jquery.com/jquery-3.4.0.min.js:2:29453)
    at t (https://code.jquery.com/jquery-3.4.0.min.js:2:29755) undefined
k.Deferred.exceptionHook @ jquery-3.4.0.min.js:2
t @ jquery-3.4.0.min.js:2
setTimeout (async)
(anonymous) @ jquery-3.4.0.min.js:2
c @ jquery-3.4.0.min.js:2
fireWith @ jquery-3.4.0.min.js:2
fire @ jquery-3.4.0.min.js:2
c @ jquery-3.4.0.min.js:2
fireWith @ jquery-3.4.0.min.js:2
ready @ jquery-3.4.0.min.js:2
B @ jquery-3.4.0.min.js:2
jquery-3.4.0.min.js:2 Uncaught ReferenceError: Waves is not defined
    at HTMLDocument.<anonymous> (wk.html:20)
    at e (jquery-3.4.0.min.js:2)
    at t (jquery-3.4.0.min.js:2)

1 Ответ

2 голосов
/ 25 мая 2019

Вам необходимо правильно инициализировать WavesKeeper и keeperAPI, поэтому на него нельзя ссылаться.

Вместо этого попробуйте этот код:

<script>
        window.WavesKeeper = Waves;

        $('document').ready(function () {
            if (typeof Waves !== 'undefined') {
                console.log('installed')
            } else {
                console.log('not installed')
            }
            $('.auth-btn').on('click', function (e) {
                WavesKeeper.auth({ name: 'Your App', data: 'Any stuff' })
                    .then(function (res) {
                        console.log(res);
                        $('#address')
                            .html('Your WAVES Address: <b>' + res.address + '</b>')
                            .removeClass('alert-danger').addClass('alert-success');
                    })
                    .catch(function (err) {
                        $('#address').html(JSON.stringify(err)).removeClass('alert-success').addClass('alert-danger');
                    });
                e.preventDefault();
            });

        });
    </script>

<a class="btn btn-primary btn-rounded auth-btn" href="#">Click to get WAVES Address</a>
        <div class="alert alert-success" id="address"></div>
...