Fix issue where rescan would be interrupted
This commit is contained in:
parent
382030db07
commit
8abf43bada
|
@ -392,6 +392,10 @@ export default class RouteApp extends React.Component<Props, AppState> {
|
|||
this.rpc.refresh(0, false);
|
||||
};
|
||||
|
||||
clearTimers = () => {
|
||||
this.rpc.clearTimers();
|
||||
};
|
||||
|
||||
render() {
|
||||
const {
|
||||
totalBalance,
|
||||
|
@ -449,6 +453,7 @@ export default class RouteApp extends React.Component<Props, AppState> {
|
|||
encryptWallet={this.encryptWallet}
|
||||
decryptWallet={this.decryptWallet}
|
||||
openPassword={this.openPassword}
|
||||
clearTimers={this.clearTimers}
|
||||
{...standardProps}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
@ -137,6 +137,7 @@ type Props = {
|
|||
setRescanning: boolean => void,
|
||||
addresses: string[],
|
||||
setInfo: Info => void,
|
||||
clearTimers: () => void,
|
||||
setSendTo: (address: string, amount: number | null, memo: string | null) => void,
|
||||
getPrivKeyAsString: (address: string) => string,
|
||||
history: PropTypes.object.isRequired,
|
||||
|
@ -175,7 +176,15 @@ class Sidebar extends PureComponent<Props, State> {
|
|||
|
||||
// Handle menu items
|
||||
setupMenuHandlers = async () => {
|
||||
const { setSendTo, setInfo, setRescanning, history, openErrorModal, openPasswordAndUnlockIfNeeded } = this.props;
|
||||
const {
|
||||
clearTimers,
|
||||
setSendTo,
|
||||
setInfo,
|
||||
setRescanning,
|
||||
history,
|
||||
openErrorModal,
|
||||
openPasswordAndUnlockIfNeeded
|
||||
} = this.props;
|
||||
|
||||
// About
|
||||
ipcRenderer.on('about', () => {
|
||||
|
@ -321,6 +330,7 @@ class Sidebar extends PureComponent<Props, State> {
|
|||
ipcRenderer.on('rescan', () => {
|
||||
// To rescan, we reset the wallet loading
|
||||
// So set info the default, and redirect to the loading screen
|
||||
clearTimers();
|
||||
RPC.doRescan();
|
||||
|
||||
// Set the rescanning global state to true
|
||||
|
|
62
app/rpc.js
62
app/rpc.js
|
@ -1,6 +1,8 @@
|
|||
// @flow
|
||||
/* eslint-disable max-classes-per-file */
|
||||
import axios from 'axios';
|
||||
import { TotalBalance, AddressBalance, Transaction, RPCConfig, TxDetail, Info } from './components/AppState';
|
||||
// $FlowFixMe
|
||||
import native from '../native/index.node';
|
||||
|
||||
export default class RPC {
|
||||
|
@ -16,11 +18,13 @@ export default class RPC {
|
|||
|
||||
fnSetAllAddresses: (string[]) => void;
|
||||
|
||||
fnSetZecPrice: number => void;
|
||||
fnSetZecPrice: (number | null) => void;
|
||||
|
||||
refreshTimerID: TimerID;
|
||||
refreshTimerID: IntervalID | null;
|
||||
|
||||
priceTimerID: TimerID;
|
||||
priceTimerID: TimeoutID | null;
|
||||
|
||||
lastBlockHeight: number;
|
||||
|
||||
constructor(
|
||||
fnSetTotalBalance: TotalBalance => void,
|
||||
|
@ -28,7 +32,7 @@ export default class RPC {
|
|||
fnSetTransactionsList: (Transaction[]) => void,
|
||||
fnSetAllAddresses: (string[]) => void,
|
||||
fnSetInfo: Info => void,
|
||||
fnSetZecPrice: number => void
|
||||
fnSetZecPrice: (number | null) => void
|
||||
) {
|
||||
this.fnSetTotalBalance = fnSetTotalBalance;
|
||||
this.fnSetAddressesWithBalance = fnSetAddressesWithBalance;
|
||||
|
@ -36,22 +40,36 @@ export default class RPC {
|
|||
this.fnSetAllAddresses = fnSetAllAddresses;
|
||||
this.fnSetInfo = fnSetInfo;
|
||||
this.fnSetZecPrice = fnSetZecPrice;
|
||||
|
||||
this.refreshTimerID = null;
|
||||
this.priceTimerID = null;
|
||||
}
|
||||
|
||||
async configure(rpcConfig: RPCConfig) {
|
||||
this.rpcConfig = rpcConfig;
|
||||
|
||||
if (!this.refreshTimerID) {
|
||||
this.refreshTimerID = setTimeout(() => this.refresh(0, true), 1000);
|
||||
this.refreshTimerID = setInterval(() => this.refresh(false), 60 * 1000);
|
||||
}
|
||||
|
||||
if (!this.priceTimerID) {
|
||||
this.priceTimerID = setTimeout(() => this.getZecPrice(), 1000);
|
||||
this.priceTimerID = setTimeout(() => this.getZecPrice(0), 1000);
|
||||
}
|
||||
|
||||
// Immediately call the refresh after configure to update the UI
|
||||
this.refresh(true);
|
||||
}
|
||||
|
||||
setupNextFetch(lastBlockHeight: number) {
|
||||
this.refreshTimerID = setTimeout(() => this.refresh(lastBlockHeight, true), 60 * 1000);
|
||||
clearTimers() {
|
||||
if (this.refreshTimerID) {
|
||||
clearInterval(this.refreshTimerID);
|
||||
this.refreshTimerID = null;
|
||||
}
|
||||
|
||||
if (this.priceTimerID) {
|
||||
clearTimeout(this.priceTimerID);
|
||||
this.priceTimerID = null;
|
||||
}
|
||||
}
|
||||
|
||||
static doSync() {
|
||||
|
@ -75,10 +93,10 @@ export default class RPC {
|
|||
console.log(`Sync status: ${savestr}`);
|
||||
}
|
||||
|
||||
async refresh(lastBlockHeight: number, setupNextOne: boolean) {
|
||||
async refresh(fullRefresh: boolean) {
|
||||
const latestBlockHeight = await this.fetchInfo();
|
||||
|
||||
if (!lastBlockHeight || lastBlockHeight < latestBlockHeight) {
|
||||
if (fullRefresh || !this.lastBlockHeight || this.lastBlockHeight < latestBlockHeight) {
|
||||
// If the latest block height has changed, make sure to sync. This will happen in a new thread
|
||||
RPC.doSync();
|
||||
|
||||
|
@ -92,26 +110,20 @@ export default class RPC {
|
|||
// Wait a max of 30 retries (30 secs)
|
||||
if (walletHeight >= latestBlockHeight || retryCount > 30) {
|
||||
// We are synced. Cancel the poll timer
|
||||
clearTimeout(pollerID);
|
||||
clearInterval(pollerID);
|
||||
|
||||
// And fetch the rest of the data.
|
||||
this.fetchTotalBalance();
|
||||
this.fetchTandZTransactions(latestBlockHeight);
|
||||
|
||||
this.lastBlockHeight = latestBlockHeight;
|
||||
// All done, set up next fetch
|
||||
console.log(`Finished full refresh at ${latestBlockHeight}`);
|
||||
|
||||
if (setupNextOne) {
|
||||
this.setupNextFetch(latestBlockHeight);
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
} else {
|
||||
// Already at the latest block
|
||||
console.log('Already have latest block, waiting for next refresh');
|
||||
if (setupNextOne) {
|
||||
this.setupNextFetch(latestBlockHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,8 +149,8 @@ export default class RPC {
|
|||
return info;
|
||||
}
|
||||
|
||||
async fetchInfo(): number {
|
||||
const info = RPC.getInfoObject(this.rpcConfig);
|
||||
async fetchInfo(): Promise<number> {
|
||||
const info = RPC.getInfoObject();
|
||||
|
||||
this.fnSetInfo(info);
|
||||
|
||||
|
@ -309,13 +321,13 @@ export default class RPC {
|
|||
throw error;
|
||||
} else {
|
||||
// And refresh data (full refresh)
|
||||
this.refresh(0, false);
|
||||
this.refresh(true);
|
||||
|
||||
return txid;
|
||||
}
|
||||
}
|
||||
|
||||
async encryptWallet(password): boolean {
|
||||
async encryptWallet(password: string): Promise<boolean> {
|
||||
const resultStr = native.litelib_execute('encrypt', password);
|
||||
const resultJSON = JSON.parse(resultStr);
|
||||
|
||||
|
@ -328,7 +340,7 @@ export default class RPC {
|
|||
return resultJSON.result === 'success';
|
||||
}
|
||||
|
||||
async decryptWallet(password): boolean {
|
||||
async decryptWallet(password: string): Promise<boolean> {
|
||||
const resultStr = native.litelib_execute('decrypt', password);
|
||||
const resultJSON = JSON.parse(resultStr);
|
||||
|
||||
|
@ -341,7 +353,7 @@ export default class RPC {
|
|||
return resultJSON.result === 'success';
|
||||
}
|
||||
|
||||
async lockWallet(): boolean {
|
||||
async lockWallet(): Promise<boolean> {
|
||||
const resultStr = native.litelib_execute('lock', '');
|
||||
const resultJSON = JSON.parse(resultStr);
|
||||
|
||||
|
@ -351,7 +363,7 @@ export default class RPC {
|
|||
return resultJSON.result === 'success';
|
||||
}
|
||||
|
||||
async unlockWallet(password: string): boolean {
|
||||
async unlockWallet(password: string): Promise<boolean> {
|
||||
const resultStr = native.litelib_execute('unlock', password);
|
||||
const resultJSON = JSON.parse(resultStr);
|
||||
|
||||
|
|
|
@ -246,7 +246,7 @@
|
|||
"eslint-plugin-testcafe": "^0.2.1",
|
||||
"fbjs-scripts": "^1.2.0",
|
||||
"file-loader": "^5.0.2",
|
||||
"flow-bin": "^0.113.0",
|
||||
"flow-bin": "^0.122.0",
|
||||
"flow-runtime": "^0.17.0",
|
||||
"flow-typed": "^2.6.2",
|
||||
"husky": "^3.1.0",
|
||||
|
|
Loading…
Reference in New Issue