mirror of https://github.com/m2049r/xmrwallet.git
Display 'Connecting...' when connection to daemon is lost
This commit is contained in:
parent
dd92f7bb36
commit
4ac01abe10
|
@ -230,7 +230,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
|
||||||
final WalletFragment walletFragment = getWalletFragment();
|
final WalletFragment walletFragment = getWalletFragment();
|
||||||
getWallet().rescanBlockchainAsync();
|
getWallet().rescanBlockchainAsync();
|
||||||
synced = false;
|
synced = false;
|
||||||
walletFragment.unsync();
|
walletFragment.onStartRescan();
|
||||||
invalidateOptionsMenu();
|
invalidateOptionsMenu();
|
||||||
} catch (ClassCastException ex) {
|
} catch (ClassCastException ex) {
|
||||||
Timber.d(ex.getLocalizedMessage());
|
Timber.d(ex.getLocalizedMessage());
|
||||||
|
|
|
@ -374,6 +374,10 @@ public class WalletFragment extends Fragment
|
||||||
bSend.setEnabled(false);
|
bSend.setEnabled(false);
|
||||||
}
|
}
|
||||||
if (isVisible()) enableAccountsList(false); //otherwise it is enabled in onResume()
|
if (isVisible()) enableAccountsList(false); //otherwise it is enabled in onResume()
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onStartRescan() {
|
||||||
|
unsync();
|
||||||
firstBlock = 0;
|
firstBlock = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -460,10 +464,17 @@ public class WalletFragment extends Fragment
|
||||||
} else {
|
} else {
|
||||||
sync = getString(R.string.status_synced) + " " + formatter.format(wallet.getBlockChainHeight());
|
sync = getString(R.string.status_synced) + " " + formatter.format(wallet.getBlockChainHeight());
|
||||||
ivSynced.setVisibility(View.VISIBLE);
|
ivSynced.setVisibility(View.VISIBLE);
|
||||||
|
setProgress(-1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sync = getString(R.string.status_wallet_connecting);
|
sync = getString(R.string.status_wallet_connecting);
|
||||||
setProgress(101);
|
setProgress(101);
|
||||||
|
ivSynced.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
if (wallet.isSynchronized()) {
|
||||||
|
onSynced();
|
||||||
|
} else {
|
||||||
|
unsync();
|
||||||
}
|
}
|
||||||
setProgress(sync);
|
setProgress(sync);
|
||||||
// TODO show connected status somewhere
|
// TODO show connected status somewhere
|
||||||
|
|
|
@ -283,6 +283,10 @@ public class Wallet {
|
||||||
this.synced = true;
|
this.synced = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUnsynchronized() {
|
||||||
|
this.synced = false;
|
||||||
|
}
|
||||||
|
|
||||||
public static native String getDisplayAmount(long amount);
|
public static native String getDisplayAmount(long amount);
|
||||||
|
|
||||||
public static native long getAmountFromString(String amount);
|
public static native long getAmountFromString(String amount);
|
||||||
|
|
|
@ -121,8 +121,9 @@ public class WalletService extends Service {
|
||||||
Timber.d("newBlock() @ %d with observer %s", height, observer);
|
Timber.d("newBlock() @ %d with observer %s", height, observer);
|
||||||
if (observer != null) {
|
if (observer != null) {
|
||||||
boolean fullRefresh = false;
|
boolean fullRefresh = false;
|
||||||
updateDaemonState(wallet, wallet.isSynchronized() ? height : 0);
|
boolean receivedNewBlock = true;
|
||||||
if (!wallet.isSynchronized()) {
|
boolean updatedWalletConnectionStatus = updateDaemonState(wallet, height, receivedNewBlock);
|
||||||
|
if (updatedWalletConnectionStatus || !wallet.isSynchronized()) {
|
||||||
updated = true;
|
updated = true;
|
||||||
// we want to see our transactions as they come in
|
// we want to see our transactions as they come in
|
||||||
wallet.refreshHistory();
|
wallet.refreshHistory();
|
||||||
|
@ -146,13 +147,13 @@ public class WalletService extends Service {
|
||||||
updated = true;
|
updated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshed() { // this means it's synced
|
public void refreshed() {
|
||||||
Timber.d("refreshed()");
|
Timber.d("refreshed()");
|
||||||
final Wallet wallet = getWallet();
|
final Wallet wallet = getWallet();
|
||||||
if (wallet == null) throw new IllegalStateException("No wallet!");
|
if (wallet == null) throw new IllegalStateException("No wallet!");
|
||||||
wallet.setSynchronized();
|
boolean receivedNewBlock = false;
|
||||||
if (updated) {
|
boolean updatedWalletConnectionStatus = updateDaemonState(wallet, wallet.getBlockChainHeight(), receivedNewBlock);
|
||||||
updateDaemonState(wallet, wallet.getBlockChainHeight());
|
if (updated || updatedWalletConnectionStatus) {
|
||||||
wallet.refreshHistory();
|
wallet.refreshHistory();
|
||||||
if (observer != null) {
|
if (observer != null) {
|
||||||
updated = !observer.onRefreshed(wallet, true);
|
updated = !observer.onRefreshed(wallet, true);
|
||||||
|
@ -164,16 +165,20 @@ public class WalletService extends Service {
|
||||||
private long lastDaemonStatusUpdate = 0;
|
private long lastDaemonStatusUpdate = 0;
|
||||||
private long daemonHeight = 0;
|
private long daemonHeight = 0;
|
||||||
private Wallet.ConnectionStatus connectionStatus = Wallet.ConnectionStatus.ConnectionStatus_Disconnected;
|
private Wallet.ConnectionStatus connectionStatus = Wallet.ConnectionStatus.ConnectionStatus_Disconnected;
|
||||||
private static final long STATUS_UPDATE_INTERVAL = 120000; // 120s (blocktime)
|
private static final long STATUS_UPDATE_INTERVAL_SYNCED = 120000; // 120s (blocktime)
|
||||||
|
private static final long STATUS_UPDATE_INTERVAL_SYNCING = 10000; // 10s
|
||||||
|
|
||||||
private void updateDaemonState(Wallet wallet, long height) {
|
private boolean updateDaemonState(Wallet wallet, long height, boolean receivedNewBlock) {
|
||||||
|
Wallet.ConnectionStatus startConnectionStatus = connectionStatus;
|
||||||
long t = System.currentTimeMillis();
|
long t = System.currentTimeMillis();
|
||||||
if (height > 0) { // if we get a height, we are connected
|
if (daemonHeight > 0 && height > 0 && (height > daemonHeight || receivedNewBlock)) {
|
||||||
daemonHeight = height;
|
if (height > daemonHeight)
|
||||||
|
daemonHeight = height;
|
||||||
connectionStatus = Wallet.ConnectionStatus.ConnectionStatus_Connected;
|
connectionStatus = Wallet.ConnectionStatus.ConnectionStatus_Connected;
|
||||||
lastDaemonStatusUpdate = t;
|
lastDaemonStatusUpdate = t;
|
||||||
} else {
|
} else {
|
||||||
if (t - lastDaemonStatusUpdate > STATUS_UPDATE_INTERVAL) {
|
long statusUpdateInterval = wallet.isSynchronized() ? STATUS_UPDATE_INTERVAL_SYNCED : STATUS_UPDATE_INTERVAL_SYNCING;
|
||||||
|
if (daemonHeight == 0 || t - lastDaemonStatusUpdate > statusUpdateInterval) {
|
||||||
lastDaemonStatusUpdate = t;
|
lastDaemonStatusUpdate = t;
|
||||||
// these calls really connect to the daemon - wasting time
|
// these calls really connect to the daemon - wasting time
|
||||||
daemonHeight = wallet.getDaemonBlockChainHeight();
|
daemonHeight = wallet.getDaemonBlockChainHeight();
|
||||||
|
@ -185,6 +190,16 @@ public class WalletService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
setWalletSyncState(wallet);
|
||||||
|
return startConnectionStatus != connectionStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWalletSyncState(Wallet wallet) {
|
||||||
|
if (daemonHeight > 0 && daemonHeight <= wallet.getBlockChainHeight()) {
|
||||||
|
wallet.setSynchronized();
|
||||||
|
} else {
|
||||||
|
wallet.setUnsynchronized();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getDaemonHeight() {
|
public long getDaemonHeight() {
|
||||||
|
|
Loading…
Reference in New Issue