zabo-api / zabo-sdk-js

Zabo is an API for connecting with cryptocurrency exchanges, wallets and protocols like Bitcoin.
https://zabo.com
MIT License
18 stars 11 forks source link

Uncaught TypeError #80

Closed mika787 closed 3 years ago

mika787 commented 3 years ago

What SDK version are you using?

1.0

What technology and versions are you using that is causing issues with the SDK?

I'm using the html script for client side

What did you do?

I copied the zabo script into my html file. I can connect to my Metamask wallet just fine. When I click the crypto balances button I get results as expected. When I click on the Account History button I get this error - "Uncaught TypeError: Cannot read property 'getList' of undefined at HTMLButtonElement." Did I leave something out? Not a professional, just trying to learn. Thanks in advance. Here is the script I used -

<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
    <meta charset="utf-8">
    <title>My Website</title>

    <title>Bootstrap 101 Template</title>

    <!-- Bootstrap -->
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
        integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
        integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>

<body>
    <section>
        <header>
            <h2 class="text-center">Tammy's Zabo Application</h2>
        </header>
        <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
        <!-- Include all compiled plugins (below), or include individual files as needed -->
        <script src="js/bootstrap.min.js"></script>

        <div class="container-fluid">
            <br>
            <div class="row">
                <div class="col-md-12 bg-light text-right">
                    <button id="connect" type="button" class="btn btn-success">Connect Wallet</button>
                </div>
            </div>
        </div>
        <br>
        <br>
        <div class="container-fluid">
            <h4>What Have I Been Up To?</h4>
            <button id="getBalance" type="button" class="btn btn-primary">Crypto Balances</button>
            <button id="getHistory" type="button" class="btn btn-warning">Account History</button>
        </div>

    </section>

    <!--Add this script to your html file-->
    <script src="https://cdn.zabo.com/latest/zabo.js"></script>

    <script type="module">
        // Wait for document to fully load
        document.onreadystatechange = async () => {
            if (document.readyState !== 'complete') { return }

            const output = document.querySelector('#output')

            // Initiate Zabo SDK, replace the `clientId` field with your team client id.
            const zabo = await Zabo.init({
                clientId: 'e0Tubz6cMC3qSAS8Zh5mkinQZ6G3FLlrIyAM44Vk0PWB854e2Xmxf5PP7TxEC73B',
                env: 'sandbox'
            })
            // Bind "connect" button
            document.querySelector('#connect').addEventListener('click', ev => {
                // Call connect when pressed and provide default .connect() window.
                zabo.connect().onConnection(account => {
                    console.log('account connected:', account)
                    bindOtherMethods()
                }).onError(error => {
                    console.error('account connection error:', error.message)
                })
            })

            // Bind buttons for the other SDK example methods [Requires a successful zabo.connect() first]
            function bindOtherMethods() {
                document.querySelector('#getBalance').addEventListener('click', ev => {
                    // Get ETH balance
                    zabo.accounts.getBalances({ tickers: [""] }).then(balances => {
                        console.log(balances)
                    }).catch(error => {
                        /* User has not yet connected or doesn't have an ether wallet */
                        console.error(error)
                    })
                })

                document.querySelector('#getHistory').addEventListener('click', ev => {
                    // Get account transactions history
                    zabo.transactions.getList({
                        ticker: '',
                        limit: 50
                    }).then(function (history) {
                        console.log(history.data)
                        /* 
                          `history` is the json object outlined below. NOTE: list_cursor is 
                          not exposed in the JS SDK. Simply call `next()` on the response
                          to paginate
                        */
                        history.next().then(moreHistory => {
                            console.log(moreHistory.data)
                        })
                    })
                        .catch(function (error) {
                            console.log(error)
                            /* See errors section for more information */
                        })
                })
            }
        }
    </script>
</body>
</html>

What did you expect to see?

What did you see instead?

dreinke commented 3 years ago

Hi @mika787! I just tested your code and it seems to work fine. I was able to connect an account and list transactions by running the exact same code you posted. The error you mentioned would be in the line zabo.transactions.getList({, suggesting that transactions is undefined. However, I didn't find any problem in your code that would trigger the error. Could you please test it again?

mika787 commented 3 years ago

Thank you for responding. I'm not at my desk right now to retest but I will as soon as I get home. I thought it was strange because the crypto balance button worked and the exchange rates button worked. The metamask account I'm testing with doesn't have a balance so would that cause the error? If so I would rather it say you don't have any transactions. Also is there a dummy account with transactions I could use for testing?

On Mon, Jul 5, 2021, 2:01 PM Davi Reinke @.***> wrote:

Hi @mika787 https://github.com/mika787! I just tested your code and it seems to work fine. I was able to connect an account and list transactions by running the exact same code you posted. The error you mentioned would be in the line zabo.transactions.getList({, suggesting that transactions is undefined. However, I didn't find any problem in your code that would trigger the error. Could you please test it again?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/zabo-api/zabo-sdk-js/issues/80#issuecomment-874094353, or unsubscribe https://github.com/notifications/unsubscribe-auth/AT45FAYU4QB7WIJ5KPHICETTWGULBANCNFSM47ZFF3QA .

dreinke commented 3 years ago

No, an account with no balance would not cause this error, it would just return an empty list of transactions. In sandbox, you can connect an exchange account (Binance, Kraken, etc.) to get dummy balances and transactions.

mika787 commented 3 years ago

Ok thanks I'll try that.

On Mon, Jul 5, 2021, 2:27 PM Davi Reinke @.***> wrote:

No, an account with no balance would not cause this error, it would just return an empty list of transactions. In sandbox, you can connect an exchange account (Binance, Kraken, etc.) to get dummy balances and transactions.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/zabo-api/zabo-sdk-js/issues/80#issuecomment-874114503, or unsubscribe https://github.com/notifications/unsubscribe-auth/AT45FA4U4MQLLC5C4K2UH7TTWGXNRANCNFSM47ZFF3QA .

mika787 commented 3 years ago

I ran the code again and I didn't get the getList error message. But I did get 'undefined' at line 95 which is console.log(moreHistory.data)

Any ideas?

On Mon, Jul 5, 2021, 2:27 PM Davi Reinke @.***> wrote:

No, an account with no balance would not cause this error, it would just return an empty list of transactions. In sandbox, you can connect an exchange account (Binance, Kraken, etc.) to get dummy balances and transactions.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/zabo-api/zabo-sdk-js/issues/80#issuecomment-874114503, or unsubscribe https://github.com/notifications/unsubscribe-auth/AT45FA4U4MQLLC5C4K2UH7TTWGXNRANCNFSM47ZFF3QA .

dreinke commented 3 years ago

This means that you don't have more transactions to paginate. If you need more info about the SDK pagination, here is the docs: https://zabo.com/docs/?javascript--zabo-client#pagination Also, here is a suggestion on how to implement a complete loop, considering the delay, last_updated_at and hasMore properties...

async function getAllTransactions (params) {
  const transactions = []

  let page
  while (true) {
    const resp = await (page ? page.next() : zabo.transactions.getList(params))

    const list = resp.data || []
    const delay = resp.delay * 1000 // ms
    const lastUpdatedAt = resp.last_updated_at

    if (delay && !lastUpdatedAt) {
      await new Promise(res => setTimeout(res, delay))
    } else {
      transactions.push(...list)
      if (!resp.hasMore) break
      page = resp
    }
  }

  return transactions
}

For now, I'll close this issue since this is not a SDK error. Feel free to drop into our Discord if you have any other questions.

mika787 commented 3 years ago

Thank you so much!

On Mon, Jul 5, 2021, 10:10 PM Davi Reinke @.***> wrote:

This means that you don't have more transactions to paginate. If you need more info about the SDK pagination, here is the docs: https://zabo.com/docs/?javascript--zabo-client#pagination Also, here is a suggestion on how to implement a complete loop, considering the delay, last_updated_at and hasMore properties...

async function getAllTransactions (params) { const transactions = []

let page while (true) { const resp = await (page ? page.next() : zabo.transactions.getList(params))

const list = resp.data || []
const delay = resp.delay * 1000 // ms
const lastUpdatedAt = resp.last_updated_at

if (delay && !lastUpdatedAt) {
  await new Promise(res => setTimeout(res, delay))
} else {
  transactions.push(...list)
  if (!resp.hasMore) break
  page = resp
}

}

return transactions}

For now, I'll close this issue since this is not a SDK error. Feel free to drop into our Discord https://zabo.com/discord if you have any other questions.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/zabo-api/zabo-sdk-js/issues/80#issuecomment-874330136, or unsubscribe https://github.com/notifications/unsubscribe-auth/AT45FA6VEZG4CHXEVRYK4W3TWINT7ANCNFSM47ZFF3QA .