Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: read beansOwing correctly #95

Merged
merged 2 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions wallet/src/rpc/src/batchQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,19 @@ export const batchVstorageQuery = (
}

const value = JSON.parse(data.value);
const latestValueStr = Object.hasOwn(value, 'values')
? value.values[value.values.length - 1]
: value;
const parsed = JSON.parse(latestValueStr);
const unserialized = Object.hasOwn(parsed, 'slots')
? unserialize(parsed)
: parsed;

const latestValueStr = value.values[value.values.length - 1];
return [
pathToKey(paths[index]),
{
blockHeight: value.blockHeight,
value: unserialize(JSON.parse(latestValueStr)),
value: unserialized,
},
];
}),
Expand Down
15 changes: 10 additions & 5 deletions wallet/src/util/WalletBackendAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,14 @@ export const makeWalletBridgeFromFollowers = (
watcher.watchLatest(
[
AgoricChainStoragePathKind.Data,
`published.beansOwing.${smartWalletKey.address}`,
`beansOwing.${smartWalletKey.address}`,
],
value => beansOwingUpdater.updateState(Number(value)),
value => {
beansOwingUpdater.updateState(Number(value));
},
err => {
console.error('error watching beansOwing', err);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we alert the user to errors like this?

What other failures are being ignored like this was?

Should watchLatest require an error handler?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should watchLatest require an error handler?

I think optional is okay, we don't need to mandate that for all consumers

Shouldn't we alert the user to errors like this? What other failures are being ignored like this was?

Good point, I guess it makes sense to do a little more than just log to console (which was the previous behavior). We have an errorHandler hook that we're passing in which shows a toast and sets the wallet state to an error, hiding purses and stuff. Now that I think about it, it's probably not overkill to do so, because if something went wrong in any part it's probably a big enough deal. Just updated the adapter to call that hook in all cases.

},
),
);
};
Expand Down Expand Up @@ -309,7 +314,7 @@ export const makeWalletBridgeFromFollowers = (
);
});

const watchPendingOffers = async () => {
const watchPendingOffers = () => {
stopWatchingHooks.push(
watcher.watchLatest<Partial<CurrentWalletRecord>>(
[
Expand All @@ -328,8 +333,8 @@ export const makeWalletBridgeFromFollowers = (
const fetchCurrent = async () => {
const resolvedFollower = await currentFollower;
await assertHasData(resolvedFollower);
void watchBeansOwing();
void watchPendingOffers();
watchBeansOwing();
watchPendingOffers();
watchChainBalances();

const latestIterable = await E(resolvedFollower).getLatestIterable();
Expand Down