January 2020
Intermediate to advanced
530 pages
11h 11m
English
The setBalance method is invoked any time we need to update the user balance in the app. The setBalance method fetches the user balance for each asset from the Stellar network and updates the app's state variables, as follows:
setBalance = (account) => { let app=this;var d = new URL(account,'http://127.0.0.1:8000/accounts/');
The setBalance method takes the user public key (account ID) as an input parameter. It captures the this object in the app parameter.
We also set the URL for fetching the account information for Horizon to http://127.0.0.1:8000/accounts/<account public key>.
Next, we call the account URL asynchronously. The response is captured and parsed into JSON as follows:
(async function main(){ await ...Read now
Unlock full access