-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add more decred stuff. #22
base: main
Are you sure you want to change the base?
Conversation
cw_decred/lib/wallet.dart
Outdated
if (synced == true) { | ||
synced = false; | ||
if (syncTimer != null) { | ||
syncTimer!.cancel(); | ||
} | ||
syncTimer = Timer.periodic(Duration(seconds: syncIntervalSyncing), | ||
(Timer t) => performBackgroundTasks()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be in checkSync()
?
Where you have the following code, can also possibly include a syncTimer?.cancel();
.
if (numPeers == 0) {
syncStatus = NotConnectedSyncStatus();
syncTimer?.cancel(); // add here
synced = false;
return false;
}
And where you have the following code
if (syncStatusCode > 4) {
syncStatus = SyncedSyncStatus();
// add this block...
if (synced == false) {
synced = true;
syncTimer?.cancel();
syncTimer = Timer.periodic(
Duration(seconds: syncIntervalSynced), (Timer t) => performBackgroundTasks());
}
...
return true;
}
The flow, I expect would be...
- At the start of the app,
synced = false, syncTimer = nil
- When sync is started,
synced
remain false,syncTimer
is initialized using 5 secs - During the periodic
checkSync()
...- if syncing stops,
i.e. numPeers == 0
, thensynced
is set to false and thesyncTimer
is set to nil. - if syncing is ongoing,
synced
remains false andsyncTimer
continues with the 5 secs interval as set when sync was started (bullet point 2 above) - if sync completes,
synced
becomes true and thesyncTimer
switches to a 30 secs interval.
- if syncing stops,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be in checkSync()?
If we wait until that returns we only need to check once, otherwise there are like 5 false returns.
if syncing stops, i.e. numPeers == 0, then synced is set to false and the syncTimer is set to nil.
Then we have to start it again or it will never check again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we have to start it again or it will never check again?
Oh, right, peers can go to 0 and automatically get back to 1+, without having to restart sync. Missed that.
Okay.
// This will not return an address if the wallet is not synced. | ||
final cAddr = libdcrwallet.currentReceiveAddress(walletInfo.name) ?? ''; | ||
if (cAddr != '') { | ||
currentAddr = cAddr; | ||
} | ||
return currentAddr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed this, so this displays a previously cached address. Is this safe/desired? I noticed that I got disconnected from the network after I used the currentReceiveAddress
to receive funds, and the receive page continued to show that address that has been used until I eventually got synced again before the address changed.
At other times, e.g. when the app is just loaded and sync hasn't completed yet, no address is displayed on the receive screen. Was thinking this was the working idea, to not show an address if the wallet is not synced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it doesn't set the current address to a blank screen if not synced. I think we did this on purpose at some point, so if you were synced and then became unsynced, you would still have the address.
If you are staring at the page, I guess that also does not update even if synced and the old one was used.
imo it's ok like it is but could be better. I think setting to blank after we already got one and we dont know if used is probably less likely to cause an issue than if the user just saw an address there and now it's gone... especially since cake seems to encourage address reuse, although we should not...
cw_decred/lib/wallet_addresses.dart
Outdated
final addrs = List<String>.from(usedAddresses); | ||
for (final k in addressesMap.keys) { | ||
addrs.add(k); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like addressesMap.keys
should be enough? Both used and unused addresses are in addressesMap
, looking at the updateAddressesInBox()
method. I wonder if this current code would cause some duplicate addresses...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, this is wrong, fixing.
final nUsed = "10"; | ||
final nUnused = "1"; | ||
final res = libdcrwallet.addresses(walletInfo.name, nUsed, nUnused); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the libwallet go code, I saw this comment...
No unused addresses are returned if nUnused is zero. All used addresses are returned if nUsed is zero.
Is there ever a time we need all used addresses? Should nUsed
return NO used addresses, rather than ALL used addresses?
I also don't see a use case for nUsed
being 0 in the dart code so far.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably zero being none makes more sense tbh. The old code returned all used and no unused, so I guess I was trying to make it like that. We probalby won't use zero either way so you can change it some time if you are doing something else in libwallet.
cw_decred/lib/wallet_addresses.dart
Outdated
final unusedAddrs = List<String>.from(decoded["unused"]); | ||
// index is the index of the first unused address. | ||
final index = decoded["index"] ?? 0; | ||
return (usedAddrs, unusedAddrs, index); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please consider using a class like this instead, so the code where this method is called will be slightly easier to understand (e.g. using res.usedAddrs instead of res.$1)...
class LibAddresses {
final List<String> usedAddrs, unusedAddrs;
final int firstUnusedAddrIndex;
LibAddresses(
{required this.usedAddrs, required this.unusedAddrs, required this.firstUnusedAddrIndex});
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok doing this.
@@ -603,7 +565,8 @@ abstract class WalletAddressListViewModelBase | |||
WalletType.haven, | |||
WalletType.bitcoinCash, | |||
WalletType.bitcoin, | |||
WalletType.litecoin | |||
WalletType.litecoin, | |||
WalletType.decred |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we doing this again? Seems like we can simply say false to hasAddressList
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the wallet is not synced (disconnected), the receive page doesn't show an address that can be used but the list of addresses shows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idk, the guy asked me to implement them, it will show used still.
I guess it makes sense to show used ones and labeling them for some people.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to see how this feature works for testnet btc but getting test coins has been a challenge. The faucet I used sent a tx with a fee that is quite lower than most txs in the mempool, so no idea when that will get mined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bitcoin testnet coins? yeah...
cw_decred/lib/wallet.dart
Outdated
addr = walletAddresses.address; | ||
} | ||
if (addr == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
walletAddresses.address
returns an empty string, not null, currently.
So the app shows Exception: unable to decode address: address "" is not a supported type
currently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks fixed.
@override | ||
set address(String addr) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Selecting an address from the list of addresses on the receive page doesn't work. I think this needs to be implemented for it to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed it because the overridden method was set address(String address) => _localAddress = address;
and I expected that would make it work, but doesnt seem so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that would only work if you also don't override get address
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tried setting the address returned by address to the thing the set argument but didnt work...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think because the getter doesn’t really retain the local variable. It gets an address from libwallet and only returns the local variable if libwallet doesn’t return an address.
I’m thinking that the following might work:
- don’t update the local variable inside the getter, only update via the setter, i.e. when a user selects a specific address.
- In the getter, if the local variable has a value, return that value. It means the user selected that address to use.
- Return an address from libwallet if the local variable is empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure I tried that. Can that scene change while looking at it? The edited names dont change until I come back.
856b2b0
to
ce1c80d
Compare
ce1c80d
to
c51e9aa
Compare
For testing same as cake-tech#1941