mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-08-12 08:30:45 -04:00
show that wallet is syncing on startup
This commit is contained in:
parent
9fb22f6d1f
commit
84c08e4c36
20 changed files with 75 additions and 50 deletions
|
@ -569,7 +569,7 @@ public final class XmrConnectionService {
|
|||
long targetHeight = lastInfo.getTargetHeight();
|
||||
long blocksLeft = targetHeight - lastInfo.getHeight();
|
||||
if (syncStartHeight == null) syncStartHeight = lastInfo.getHeight();
|
||||
double percent = ((double) Math.max(1, lastInfo.getHeight() - syncStartHeight) / (double) (targetHeight - syncStartHeight)) * 100d; // grant at least 1 block to show progress
|
||||
double percent = targetHeight == syncStartHeight ? 1.0 : ((double) Math.max(1, lastInfo.getHeight() - syncStartHeight) / (double) (targetHeight - syncStartHeight)) * 100d; // grant at least 1 block to show progress
|
||||
downloadListener.progress(percent, blocksLeft, null);
|
||||
}
|
||||
|
||||
|
|
|
@ -401,6 +401,7 @@ public class HavenoSetup {
|
|||
|
||||
// reset startup timeout on progress
|
||||
getXmrDaemonSyncProgress().addListener((observable, oldValue, newValue) -> resetStartupTimeout());
|
||||
getXmrWalletSyncProgress().addListener((observable, oldValue, newValue) -> resetStartupTimeout());
|
||||
|
||||
log.info("Init P2P network");
|
||||
havenoSetupListeners.forEach(HavenoSetupListener::onInitP2pNetwork);
|
||||
|
@ -727,6 +728,10 @@ public class HavenoSetup {
|
|||
return walletAppSetup.getXmrDaemonSyncProgress();
|
||||
}
|
||||
|
||||
public DoubleProperty getXmrWalletSyncProgress() {
|
||||
return walletAppSetup.getXmrWalletSyncProgress();
|
||||
}
|
||||
|
||||
public StringProperty getWalletServiceErrorMsg() {
|
||||
return walletAppSetup.getWalletServiceErrorMsg();
|
||||
}
|
||||
|
|
|
@ -71,6 +71,8 @@ public class WalletAppSetup {
|
|||
@Getter
|
||||
private final DoubleProperty xmrDaemonSyncProgress = new SimpleDoubleProperty(-1);
|
||||
@Getter
|
||||
private final DoubleProperty xmrWalletSyncProgress = new SimpleDoubleProperty(-1);
|
||||
@Getter
|
||||
private final StringProperty walletServiceErrorMsg = new SimpleStringProperty();
|
||||
@Getter
|
||||
private final StringProperty xmrSplashSyncIconId = new SimpleStringProperty();
|
||||
|
@ -117,29 +119,42 @@ public class WalletAppSetup {
|
|||
String result;
|
||||
if (exception == null && errorMsg == null) {
|
||||
|
||||
// TODO: update for daemon and wallet sync progress
|
||||
double chainDownloadPercentageD = (double) chainDownloadPercentage;
|
||||
xmrDaemonSyncProgress.set(chainDownloadPercentageD);
|
||||
Long bestChainHeight = chainHeight == null ? null : (Long) chainHeight;
|
||||
String chainHeightAsString = bestChainHeight != null && bestChainHeight > 0 ?
|
||||
String.valueOf(bestChainHeight) :
|
||||
"";
|
||||
if (chainDownloadPercentageD == 1) {
|
||||
String synchronizedWith = Res.get("mainView.footer.xmrInfo.synchronizedWith",
|
||||
getXmrNetworkAsString(), chainHeightAsString);
|
||||
// update wallet sync progress
|
||||
double walletDownloadPercentageD = (double) walletDownloadPercentage;
|
||||
xmrWalletSyncProgress.set(walletDownloadPercentageD);
|
||||
Long bestWalletHeight = walletHeight == null ? null : (Long) walletHeight;
|
||||
String walletHeightAsString = bestWalletHeight != null && bestWalletHeight > 0 ? String.valueOf(bestWalletHeight) : "";
|
||||
if (walletDownloadPercentageD == 1) {
|
||||
String synchronizedWith = Res.get("mainView.footer.xmrInfo.synchronizedWalletWith", getXmrNetworkAsString(), walletHeightAsString);
|
||||
String feeInfo = ""; // TODO: feeService.isFeeAvailable() returns true, disable
|
||||
result = Res.get("mainView.footer.xmrInfo", synchronizedWith, feeInfo);
|
||||
getXmrSplashSyncIconId().set("image-connection-synced");
|
||||
downloadCompleteHandler.run();
|
||||
} else if (chainDownloadPercentageD > 0.0) {
|
||||
String synchronizingWith = Res.get("mainView.footer.xmrInfo.synchronizingWith",
|
||||
getXmrNetworkAsString(), chainHeightAsString,
|
||||
FormattingUtils.formatToRoundedPercentWithSymbol(chainDownloadPercentageD));
|
||||
result = Res.get("mainView.footer.xmrInfo", synchronizingWith, "");
|
||||
} else if (walletDownloadPercentageD > 0) {
|
||||
result = "Synchronizing wallet ..."; // TODO: support wallet progress updates and use below translation
|
||||
// String synchronizingWith = Res.get("mainView.footer.xmrInfo.synchronizingWalletWith", getXmrNetworkAsString(), walletHeightAsString, FormattingUtils.formatToRoundedPercentWithSymbol(walletDownloadPercentageD));
|
||||
// result = Res.get("mainView.footer.xmrInfo", synchronizingWith, "");
|
||||
getXmrSplashSyncIconId().set(""); // clear synced icon
|
||||
} else {
|
||||
result = Res.get("mainView.footer.xmrInfo",
|
||||
Res.get("mainView.footer.xmrInfo.connectingTo"),
|
||||
getXmrNetworkAsString());
|
||||
|
||||
// update daemon sync progress
|
||||
double chainDownloadPercentageD = (double) chainDownloadPercentage;
|
||||
xmrDaemonSyncProgress.set(chainDownloadPercentageD);
|
||||
Long bestChainHeight = chainHeight == null ? null : (Long) chainHeight;
|
||||
String chainHeightAsString = bestChainHeight != null && bestChainHeight > 0 ? String.valueOf(bestChainHeight) : "";
|
||||
if (chainDownloadPercentageD == 1) {
|
||||
String synchronizedWith = Res.get("mainView.footer.xmrInfo.synchronizedDaemonWith", getXmrNetworkAsString(), chainHeightAsString);
|
||||
String feeInfo = ""; // TODO: feeService.isFeeAvailable() returns true, disable
|
||||
result = Res.get("mainView.footer.xmrInfo", synchronizedWith, feeInfo);
|
||||
getXmrSplashSyncIconId().set("image-connection-synced");
|
||||
} else if (chainDownloadPercentageD > 0.0) {
|
||||
String synchronizingWith = Res.get("mainView.footer.xmrInfo.synchronizingDaemonWith", getXmrNetworkAsString(), chainHeightAsString, FormattingUtils.formatToRoundedPercentWithSymbol(chainDownloadPercentageD));
|
||||
result = Res.get("mainView.footer.xmrInfo", synchronizingWith, "");
|
||||
} else {
|
||||
result = Res.get("mainView.footer.xmrInfo",
|
||||
Res.get("mainView.footer.xmrInfo.connectingTo"),
|
||||
getXmrNetworkAsString());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result = Res.get("mainView.footer.xmrInfo",
|
||||
|
|
|
@ -125,6 +125,7 @@ public class XmrWalletService {
|
|||
private final Map<String, Optional<MoneroTx>> txCache = new HashMap<String, Optional<MoneroTx>>();
|
||||
private boolean isShutDownStarted = false;
|
||||
private ExecutorService syncWalletThreadPool = Executors.newFixedThreadPool(10); // TODO: adjust based on connection type
|
||||
private Long syncStartHeight = null;
|
||||
|
||||
@Inject
|
||||
XmrWalletService(Preferences preferences,
|
||||
|
@ -724,9 +725,10 @@ public class XmrWalletService {
|
|||
// sync main wallet if applicable
|
||||
if (sync && numAttempts > 0) {
|
||||
try {
|
||||
|
||||
|
||||
// sync main wallet
|
||||
log.info("Syncing main wallet");
|
||||
updateSyncProgress();
|
||||
long time = System.currentTimeMillis();
|
||||
wallet.sync(); // blocking
|
||||
walletHeight.set(wallet.getHeight());
|
||||
|
@ -775,6 +777,15 @@ public class XmrWalletService {
|
|||
}
|
||||
}
|
||||
|
||||
private void updateSyncProgress() {
|
||||
walletHeight.set(wallet.getHeight());
|
||||
long targetHeight = xmrConnectionService.getTargetHeight();
|
||||
long blocksLeft = targetHeight - walletHeight.get();
|
||||
if (syncStartHeight == null) syncStartHeight = walletHeight.get();
|
||||
double percent = targetHeight == syncStartHeight ? 1.0 : ((double) Math.max(1, walletHeight.get() - syncStartHeight) / (double) (targetHeight - syncStartHeight)) * 100d; // grant at least 1 block to show progress
|
||||
downloadListener.progress(percent, blocksLeft, null);
|
||||
}
|
||||
|
||||
private MoneroWalletRpc createWalletRpc(MoneroWalletConfig config, Integer port) {
|
||||
|
||||
// must be connected to daemon
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue