Skip to content

Commit 8e54e84

Browse files
authored
Merge pull request #9951 from matiu/bug/update-after-send
Bug/update after send
2 parents 1baa99a + f62e470 commit 8e54e84

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,4 +314,4 @@
314314
"prettier": {
315315
"singleQuote": true
316316
}
317-
}
317+
}

src/pages/home/home.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe('HomePage', () => {
5656
);
5757
expect(subscribeSpy).toHaveBeenCalledWith(
5858
'Local/TxAction',
59-
instance.walletFocusHandler
59+
instance.walletActionHandler
6060
);
6161
expect(subscribeSpy).toHaveBeenCalledWith(
6262
'Local/WalletFocus',

src/pages/home/home.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ export class HomePage {
182182
this.fetchWalletStatus(opts);
183183
};
184184

185+
private walletActionHandler = opts => {
186+
this.logger.debug('RECV Local/TxAction @home', opts);
187+
opts = opts || {};
188+
opts.alsoUpdateHistory = true;
189+
this.fetchWalletStatus(opts);
190+
};
191+
185192
ionViewDidLoad() {
186193
this.logger.info('Loaded: HomePage');
187194

@@ -202,7 +209,7 @@ export class HomePage {
202209
this.events.subscribe('Local/WalletListChange', this.setWallets);
203210

204211
// Reject, Remove, OnlyPublish and SignAndBroadcast -> Update Status per Wallet -> Update txps
205-
this.events.subscribe('Local/TxAction', this.walletFocusHandler);
212+
this.events.subscribe('Local/TxAction', this.walletActionHandler);
206213

207214
// Wallet is focused on some inner view, therefore, we refresh its status and txs
208215
this.events.subscribe('Local/WalletFocus', this.walletFocusHandler);
@@ -620,16 +627,19 @@ export class HomePage {
620627
}
621628
})
622629
.catch(err => {
623-
this.processWalletError(wallet, err);
630+
if (err == 'INPROGRESS') return;
631+
632+
this.logger.warn('Update error:', err);
624633

634+
this.processWalletError(wallet, err);
625635
this.events.publish('Local/WalletUpdate', {
626636
walletId: opts.walletId,
627637
finished: true,
628638
error: wallet.error
629639
});
630640

631641
if (opts.alsoUpdateHistory) {
632-
this.fetchTxHistory({ walletId: opts.walletId });
642+
this.fetchTxHistory({ walletId: opts.walletId, force: opts.force });
633643
}
634644
});
635645
};

src/providers/wallet/wallet.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class WalletProvider {
8484
// Ratio of "many utxos" warning in total balance (fee/amount)
8585
private TOTAL_LOW_WARNING_RATIO: number = 0.3;
8686

87-
private WALLET_STATUS_MAX_TRIES: number = 10;
87+
private WALLET_STATUS_MAX_TRIES: number = 5;
8888
private WALLET_STATUS_DELAY_BETWEEN_TRIES: number = 1.6 * 1000;
8989
private SOFT_CONFIRMATION_LIMIT: number = 12;
9090
private SAFE_CONFIRMATIONS: number = 6;
@@ -319,6 +319,10 @@ export class WalletProvider {
319319
let diff = false;
320320
_.each(s1, (v, k) => {
321321
if (s2[k] == v) diff = true;
322+
else
323+
this.logger.debug(
324+
`Status condition not meet: ${k} is ${s2[k]} not ${v}`
325+
);
322326
});
323327

324328
return diff;
@@ -976,6 +980,10 @@ export class WalletProvider {
976980
});
977981
}
978982

983+
private isHistoryCached(wallet): boolean {
984+
return wallet.completeHistory && wallet.completeHistoryIsValid;
985+
}
986+
979987
public getTx(wallet, txid: string): Promise<any> {
980988
return new Promise((resolve, reject) => {
981989
const finish = list => {
@@ -987,7 +995,7 @@ export class WalletProvider {
987995
return tx;
988996
};
989997

990-
if (wallet.completeHistory && wallet.completeHistoryIsValid) {
998+
if (this.isHistoryCached(wallet)) {
991999
const tx = finish(wallet.completeHistory);
9921000
return resolve(tx);
9931001
} else {
@@ -1016,11 +1024,8 @@ export class WalletProvider {
10161024

10171025
if (!wallet.isComplete()) return resolve();
10181026

1019-
const isHistoryCached = () => {
1020-
return wallet.completeHistory && wallet.completeHistoryIsValid;
1021-
};
1022-
1023-
if (isHistoryCached() && !opts.force) {
1027+
if (this.isHistoryCached(wallet) && !opts.force) {
1028+
this.logger.debug('Returning cached history for ' + wallet.id);
10241029
return resolve(wallet.completeHistory);
10251030
}
10261031

0 commit comments

Comments
 (0)