Merge pull request #127 from MutinyWallet/optimistic-balance

optimistic balance fetching at setup
This commit is contained in:
Paul Miller
2023-05-15 09:13:35 -05:00
committed by GitHub

View File

@@ -87,7 +87,9 @@ export const Provider: ParentComponent = (props) => {
try {
setState({ wallet_loading: true })
const mutinyWallet = await setupMutinyWallet(settings)
setState({ mutiny_wallet: mutinyWallet, wallet_loading: false })
// Get balance optimistically
const balance = await mutinyWallet.get_balance();
setState({ mutiny_wallet: mutinyWallet, wallet_loading: false, balance })
} catch (e) {
console.error(e)
}
@@ -111,8 +113,8 @@ export const Provider: ParentComponent = (props) => {
if (state.mutiny_wallet && !state.is_syncing) {
setState({ is_syncing: true })
await state.mutiny_wallet?.sync()
const balance = await state.mutiny_wallet?.get_balance();
setState({ balance, last_sync: Date.now() })
const newBalance = await state.mutiny_wallet?.get_balance();
setState({ balance: newBalance, last_sync: Date.now() })
}
} catch (e) {
console.error(e);