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

Add more decred stuff. #22

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Add more decred stuff. #22

wants to merge 7 commits into from

Conversation

JoeGruffins
Copy link
Owner

For testing same as cake-tech#1941

Comment on lines 113 to 115
if (synced == true) {
synced = false;
if (syncTimer != null) {
syncTimer!.cancel();
}
syncTimer = Timer.periodic(Duration(seconds: syncIntervalSyncing),
(Timer t) => performBackgroundTasks());
}
Copy link
Collaborator

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, then synced is set to false and the syncTimer is set to nil.
    • if syncing is ongoing, synced remains false and syncTimer continues with the 5 secs interval as set when sync was started (bullet point 2 above)
    • if sync completes, synced becomes true and the syncTimer switches to a 30 secs interval.

Copy link
Owner Author

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?

Copy link
Collaborator

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.

Comment on lines +15 to 21
// This will not return an address if the wallet is not synced.
final cAddr = libdcrwallet.currentReceiveAddress(walletInfo.name) ?? '';
if (cAddr != '') {
currentAddr = cAddr;
}
return currentAddr;
Copy link
Collaborator

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.

Copy link
Owner Author

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...

Comment on lines 79 to 82
final addrs = List<String>.from(usedAddresses);
for (final k in addressesMap.keys) {
addrs.add(k);
}
Copy link
Collaborator

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...

Copy link
Owner Author

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.

Comment on lines +99 to +97
final nUsed = "10";
final nUnused = "1";
final res = libdcrwallet.addresses(walletInfo.name, nUsed, nUnused);
Copy link
Collaborator

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.

Copy link
Owner Author

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.

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);
Copy link
Collaborator

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});
}

Copy link
Owner Author

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
Copy link
Collaborator

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...

Copy link
Collaborator

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.

Copy link
Owner Author

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.

Copy link
Collaborator

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.

Copy link
Owner Author

Choose a reason for hiding this comment

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

bitcoin testnet coins? yeah...

Comment on lines 529 to 530
addr = walletAddresses.address;
}
if (addr == null) {
Copy link
Collaborator

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.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Thanks fixed.

Comment on lines -35 to -37
@override
set address(String addr) {}
Copy link
Collaborator

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.

Copy link
Owner Author

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.

Copy link
Collaborator

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.

Copy link
Owner Author

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...

Copy link
Collaborator

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.

Copy link
Owner Author

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.

@JoeGruffins JoeGruffins force-pushed the updateaddresses.simnet branch from 856b2b0 to ce1c80d Compare January 8, 2025 05:50
@JoeGruffins JoeGruffins force-pushed the updateaddresses.simnet branch from ce1c80d to c51e9aa Compare January 8, 2025 07:38
@JoeGruffins
Copy link
Owner Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants