Open rok5ek opened 2 years ago
There are two ways to update a wallet. You can build the wallet and sync it with the blockchain in one call:
Result<Wallet, String> result = await walletBuilder.buildAndSync();
if (result.isOk()) {
var wallet = result.unwrap();
print("${wallet.walletName}: ${wallet.balance}");
}
or you can do it in two steps. First call build() which returns an empty wallet immediately. Then call update() to sync with the blockchain which is an async call:
Result<Wallet, String> result = walletBuilder.build();
Wallet wallet = result.unwrap();
Coin oldBalance = wallet.balance;
var result2 = await wallet.update();
result2.when(
ok: (_) => print("old:$oldBalance lovelace, new: ${wallet.balance} lovelace"),
err: (message) => print("Error: $message"),
);
For better performance, you could wrap the update() call in an isolate following the pattern outlined here: https://github.com/dart-lang/samples/blob/master/isolates/bin/send_and_receive.dart
Hi when I build the wallet the whole app UI freezes. Can you fix the wallet build method so it will be async?