Skip to content

Commit

Permalink
wallet: get node info for height on node refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
rithvikvibhu committed Feb 1, 2022
1 parent 2cea758 commit 63b780b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/background/node/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,13 @@ export class NodeService extends EventEmitter {

try {
const info = await this.getInfo();
this.emit('refreshNodeInfo', info);

dispatchToMainWindow({
type: SET_NODE_INFO,
payload: info.chain,
});


if (info.chain.progress > 0.99) {
const fees = await this.getFees();

Expand Down
21 changes: 20 additions & 1 deletion app/background/wallet/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ class WalletService {
nodeService.on('start remote', this._useWalletNode);
nodeService.on('start local', this._usePlugin);
nodeService.on('stopped', this._onNodeStop);
nodeService.on('refreshNodeInfo', this._onRefreshNodeInfo);
this.nodeService = nodeService;
this.nodeHeight = 0;
this.lastProgressUpdate = 0;
this.lastKnownChainHeight = 0;
this.conn = {type: null};
Expand Down Expand Up @@ -237,6 +239,23 @@ class WalletService {
this.conn = {type: null};
};

// Called when node emits refreshNodeInfo
// Required to get node height once node is connected
_onRefreshNodeInfo = async (nodeInfo) => {
this.nodeHeight = nodeInfo.chain.height;

// If wallet is synced up with node,
// stop wallet sync (similar to onRescanBlock)
if (this.lastKnownChainHeight === this.nodeHeight) {
dispatchToMainWindow({type: STOP_SYNC_WALLET});
dispatchToMainWindow({
type: SYNC_WALLET_PROGRESS,
payload: this.nodeHeight,
});
await this.refreshWalletInfo();
}
}

isReady = async () => {
let attempts = 0;
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -1065,7 +1084,7 @@ class WalletService {
onRescanBlock = async (entry) => {
this.lastKnownChainHeight = entry.height;

if (entry.height === nodeService.height) {
if (entry.height === this.nodeHeight) {
dispatchToMainWindow({type: STOP_SYNC_WALLET});
dispatchToMainWindow({
type: SYNC_WALLET_PROGRESS,
Expand Down

0 comments on commit 63b780b

Please sign in to comment.