Skip to content

Commit 5313ecb

Browse files
authored
Fix balance query in the fungible web demo. (#4438)
## Motivation Code assumed that the owner is at 0-th index. ## Proposal Specify owner for the balance query instead of assuming it's at 0-th index ## Test Plan Manual. ## Release Plan - Nothing to do / These changes follow the usual release cycle. - These changes should be backported to the latest `devnet` branch - These changes should be backported to the latest `testnet` branch - ## Links - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent 2a5c398 commit 5313ecb

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

examples/native-fungible/index.html

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

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

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

230230
const application = await client.frontend().application(import.meta.env.LINERA_APPLICATION_ID);
231231

232-
await updateBalance(application);
232+
await updateBalance(application, owner);
233233

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

241241
submitButton.disabled = false;

0 commit comments

Comments
 (0)