Skip to content

Commit bd03de3

Browse files
authored
Specify owner for the balance query (#58)
1 parent 023f2fd commit bd03de3

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

examples/hosted-fungible/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,11 @@ <h2>Chain history for <code id="chain-id" class="hex">requesting a new microchai
159159
parent.insertBefore(entry, parent.firstChild);
160160
}
161161

162-
async function updateBalance(application) {
163-
const response = JSON.parse(await application.query(gql(`query { tickerSymbol, accounts { entries { key value } } }`)));
162+
async function updateBalance(application, owner) {
163+
const response = JSON.parse(await application.query(gql(`query { tickerSymbol, accounts { entry(key: "${owner}") { value } } }`)));
164164
console.debug('application response:', response);
165165
document.querySelector('#ticker-symbol').textContent = response.data.tickerSymbol;
166-
document.querySelector('#balance').textContent = (+(response?.data?.accounts?.entries?.[0]?.value || 0)).toFixed(2);
166+
document.querySelector('#balance').textContent = (+( response.data.accounts.entry?.value || 0)).toFixed(2);
167167
}
168168

169169
async function transfer(application, donor, amount, recipient) {
@@ -232,13 +232,13 @@ <h2>Chain history for <code id="chain-id" class="hex">requesting a new microchai
232232

233233
const application = await client.frontend().application(FUNGIBLE_APP_ID);
234234

235-
await updateBalance(application);
235+
await updateBalance(application, owner);
236236

237237
client.onNotification(notification => {
238238
let newBlock = notification.reason.NewBlock;
239239
if (!newBlock) return;
240240
prependEntry(document.querySelector('#logs'), newBlock);
241-
updateBalance(application);
241+
updateBalance(application, owner);
242242
});
243243

244244
submitButton.disabled = false;

0 commit comments

Comments
 (0)