From e0de1bd6e9356d49fd14ee20012b0b9599e97f7f Mon Sep 17 00:00:00 2001 From: vantuz-subhuman Date: Fri, 2 Feb 2024 18:51:39 +0300 Subject: [PATCH 1/3] parallel wallet init --- packages/yoroi-extension/app/stores/toplevel/WalletStore.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/yoroi-extension/app/stores/toplevel/WalletStore.js b/packages/yoroi-extension/app/stores/toplevel/WalletStore.js index 068304ecc9..7078d0d11b 100644 --- a/packages/yoroi-extension/app/stores/toplevel/WalletStore.js +++ b/packages/yoroi-extension/app/stores/toplevel/WalletStore.js @@ -327,9 +327,8 @@ export default class WalletStore extends Store { this.publicDerivers.push(...newWithCachedData); }); setTimeout(async () => { - for (const publicDeriver of newWithCachedData) { - await this.refreshWalletFromLocalOnLaunch(publicDeriver); - } + await Promise.all(newWithCachedData + .map(w => this.refreshWalletFromLocalOnLaunch(w))); // This should correctly handle both states of `paralletSync`, both // initially and when it changes. // The initial case is straightforward. From 6d7f04ab4116a461da0276d6fd53f33fb63238e4 Mon Sep 17 00:00:00 2001 From: vantuz-subhuman Date: Fri, 2 Feb 2024 18:52:39 +0300 Subject: [PATCH 2/3] adding processed withdrawals fix --- .../app/stores/toplevel/TransactionsStore.js | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/yoroi-extension/app/stores/toplevel/TransactionsStore.js b/packages/yoroi-extension/app/stores/toplevel/TransactionsStore.js index c7e42b0ac0..596e031e79 100644 --- a/packages/yoroi-extension/app/stores/toplevel/TransactionsStore.js +++ b/packages/yoroi-extension/app/stores/toplevel/TransactionsStore.js @@ -286,13 +286,13 @@ export default class TransactionsStore extends Store { ) => Promise = async (result: Array, publicDeriver: PublicDeriver<>) => { const timestamps: Set = new Set(); const remoteTransactionIds: Set = new Set(); - let walletHasWithdrawal = false; + const withdrawalIds = new Set(); for (const tx of result) { const { txid, date } = tx; timestamps.add(date.valueOf()); remoteTransactionIds.add(txid); if (tx instanceof CardanoShelleyTransaction && tx.withdrawals.length > 0) { - walletHasWithdrawal = true; + withdrawalIds.add(txid); } } const defaultTokenInfo = this.stores.tokenInfoStore.getDefaultTokenInfo( @@ -309,12 +309,15 @@ export default class TransactionsStore extends Store { }); let submittedTransactionsChanged = false; + let addedProcessedWithdrawal = false; runInAction(() => { for (let i = 0; i < this._submittedTransactions.length; ) { - if (remoteTransactionIds.has(this._submittedTransactions[i].transaction.txid)) { - if (walletHasWithdrawal) { + const txId = this._submittedTransactions[i].transaction.txid; + if (remoteTransactionIds.has(txId)) { + if (withdrawalIds.has(txId) && !addedProcessedWithdrawal) { // Set local processed withdrawals only if there was a pending local transaction this._processedWithdrawals.push(publicDeriver.publicDeriverId); + addedProcessedWithdrawal = true; } this._submittedTransactions.splice(i, 1); submittedTransactionsChanged = true; @@ -472,10 +475,15 @@ export default class TransactionsStore extends Store { return newMultiToken(defaultToken); }, }); - this.stores.substores.ada.delegation.refreshDelegation(request.publicDeriver); + const refreshDelegationPromise = + this.stores.substores.ada.delegation.refreshDelegation(request.publicDeriver); if (!getBalanceRequest.promise || !getAssetDepositRequest.promise) throw new Error('should never happen'); - await Promise.all([getBalanceRequest.promise, getAssetDepositRequest.promise]); + await Promise.all([ + getBalanceRequest.promise, + getAssetDepositRequest.promise, + refreshDelegationPromise, + ]); })(); await this._afterLoadingNewTxs( From 309eadbf450902faa530834e1565dbdf78cca4e0 Mon Sep 17 00:00:00 2001 From: vantuz-subhuman Date: Fri, 2 Feb 2024 19:12:15 +0300 Subject: [PATCH 3/3] tail sync fix --- .../app/stores/ada/AdaDelegationStore.js | 4 +--- .../app/stores/toplevel/TransactionsStore.js | 20 ++++++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/yoroi-extension/app/stores/ada/AdaDelegationStore.js b/packages/yoroi-extension/app/stores/ada/AdaDelegationStore.js index 5acc0b761c..3761901f93 100644 --- a/packages/yoroi-extension/app/stores/ada/AdaDelegationStore.js +++ b/packages/yoroi-extension/app/stores/ada/AdaDelegationStore.js @@ -145,9 +145,7 @@ export default class AdaDelegationStore extends Store { publicDeriver: withStakingKey, rewardBalance: new MultiToken( [{ - amount: new BigNumber(stateForStakingKey == null - ? 0 - : stateForStakingKey.remainingAmount), + amount: new BigNumber(stateForStakingKey?.remainingAmount ?? 0), networkId: defaultToken.defaultNetworkId, identifier: defaultToken.defaultIdentifier, }], diff --git a/packages/yoroi-extension/app/stores/toplevel/TransactionsStore.js b/packages/yoroi-extension/app/stores/toplevel/TransactionsStore.js index 596e031e79..53f5876a48 100644 --- a/packages/yoroi-extension/app/stores/toplevel/TransactionsStore.js +++ b/packages/yoroi-extension/app/stores/toplevel/TransactionsStore.js @@ -362,7 +362,10 @@ export default class TransactionsStore extends Store { /* * TAIL REQUEST IS USED WHEN FIRST SYNC OR EMPTY WALLET */ - result = await this._internalTailRequestForTxs(request.publicDeriver); + result = await this._internalTailRequestForTxs({ + publicDeriver: request.publicDeriver, + isLocalRequest: request.isLocalRequest, + }); } else { /* * HEAD REQUEST IS USED WITH `AFTER` REFERENCE @@ -371,6 +374,7 @@ export default class TransactionsStore extends Store { headRequest.invalidate({ immediately: false }); headRequest.execute({ publicDeriver, + // HEAD request is never local by logic isLocalRequest: false, afterTx: txHistoryState.txs[0], }); @@ -492,11 +496,13 @@ export default class TransactionsStore extends Store { ); } - _internalTailRequestForTxs: ( - PublicDeriver<> & IGetLastSyncInfo, - ) => Promise = async ( + _internalTailRequestForTxs: ({| publicDeriver: PublicDeriver<> & IGetLastSyncInfo, - ) => { + isLocalRequest?: boolean, + |}) => Promise = async ({ + publicDeriver, + isLocalRequest = false, + }) => { const withLevels = asHasLevels(publicDeriver); if (withLevels == null) { throw new Error(`${nameof(this._loadMore)} no levels`); @@ -509,7 +515,7 @@ export default class TransactionsStore extends Store { tailRequest.invalidate({ immediately: false }); tailRequest.execute({ publicDeriver: withLevels, - isLocalRequest: false, + isLocalRequest, beforeTx, }); if (!tailRequest.promise) throw new Error('unexpected nullish tailRequest.promise'); @@ -526,7 +532,7 @@ export default class TransactionsStore extends Store { ) => Promise = async ( publicDeriver: PublicDeriver<> & IGetLastSyncInfo, ) => { - const result = await this._internalTailRequestForTxs(publicDeriver); + const result = await this._internalTailRequestForTxs({ publicDeriver }); await this._afterLoadingNewTxs(result, publicDeriver); }