r/Scriptable • • Feb 28 '22
Solved Error in debank script that used to work. Help?
Code:
var wallet = ['your wallet here']; var n = 0; var usd = 0; var strong = 0; while (n < wallet.length) { var balance_url = 'https://openapi.debank.com/v1/user/protocol?id=0xD5d9B7CbF5C5a8b750492d2746c8Af6dAD972Cf2&protocol_id=strongblock' // + wallet[n] + '&protocol_id=strongblock' ; const req = new Request(balance_url); const data = await req.loadJSON(); console.log(data); var resp = data; var total_cnt = resp['portfolio_item_list'].length; console.log(total_cnt); var i =0; while (i < total_cnt) { usd = usd + resp['portfolio_item_list'][i]['stats']['asset_usd_value']; strong = strong + resp['portfolio_item_list'][i]['detail']['token_list'][0]['amount']; i = i+1; } n =n +1; } if (config.runsInWidget) { const widget = new ListWidget(); widget.backgroundColor=new Color("#222222"); const title = widget.addText("Strong rewards"); title.textColor = Color.white(); title.textOpacity = 0.8; title.font = new Font("Helvetica-Light ", 10); widget.addSpacer(4); const strongtext = widget.addText(STRONG: ${strong.toFixed(2)}); strongtext.textColor = Color.white(); strongtext.font = new Font("Courier", 14); widget.addSpacer(2); const usdtext = widget.addText(USD: ${usd.toFixed(2)}); usdtext.textColor = Color.white(); usdtext.font = new Font("Courier", 14); Script.setWidget(widget); Script.complete(); widget.presentMedium() }
The error is this line (17)
strong = strong + resp['portfolio_item_list'][i]['detail']['token_list'][0]['amount'];
Type Error: undefined is not an object (evaluating ‘resp['portfolio_item_list'][i]['detail']['token_list'][0]’)
Any ideas?? 🙏🙏🙏🇺🇦
