diff --git a/packages/wallet/src/Wallets/BaseWallet.ts b/packages/wallet/src/Wallets/BaseWallet.ts index 92368a9b689..4935e604561 100644 --- a/packages/wallet/src/Wallets/BaseWallet.ts +++ b/packages/wallet/src/Wallets/BaseWallet.ts @@ -88,6 +88,7 @@ import { map, mergeMap, of, + shareReplay, switchMap, take, tap, @@ -474,7 +475,9 @@ export class BaseWallet implements ObservableWallet { ); const addresses$ = this.addresses$.pipe( - map((addresses) => addresses.map((groupedAddress) => groupedAddress.address)) + map((addresses) => addresses.map((groupedAddress) => groupedAddress.address)), + distinctUntilChanged(deepEquals), + shareReplay(1) ); this.#failedFromReemitter$ = new Subject(); this.transactions = createTransactionsTracker({ diff --git a/packages/wallet/src/services/UtxoTracker.ts b/packages/wallet/src/services/UtxoTracker.ts index cf48381cbe9..13bd749dede 100644 --- a/packages/wallet/src/services/UtxoTracker.ts +++ b/packages/wallet/src/services/UtxoTracker.ts @@ -1,6 +1,6 @@ import { Cardano, UtxoProvider } from '@cardano-sdk/core'; import { Logger } from 'ts-log'; -import { NEVER, Observable, combineLatest, concat, distinctUntilChanged, map, of, switchMap } from 'rxjs'; +import { NEVER, Observable, combineLatest, concat, distinctUntilChanged, map, of, shareReplay, switchMap } from 'rxjs'; import { PersistentCollectionTrackerSubject, txInEquals, utxoEquals } from './util'; import { RetryBackoffConfig } from 'backoff-rxjs'; import { TxInFlight, UtxoTracker } from './types'; @@ -121,7 +121,9 @@ export const createUtxoTracker = ( logger.debug('Found duplicate UTxO in', utxo); } return uniqueUtxo; - }) + }), + distinctUntilChanged((previous, current) => utxoEquals(previous, current)), + shareReplay(1) ); const available$ = combineLatest([total$, unspendableUtxoSource$]).pipe( // filter to utxo that are not included in in-flight transactions or unspendable @@ -131,7 +133,9 @@ export const createUtxoTracker = ( txInIsUnspendable && logger.debug('Exclude unspendable UTXO from availble$', utxoTxIn); return !txInIsUnspendable; }) - ) + ), + distinctUntilChanged((previous, current) => utxoEquals(previous, current)), + shareReplay(1) ); return { @@ -150,7 +154,8 @@ export const createUtxoTracker = ( map(([unspendableUtxo, utxo]) => unspendableUtxo.filter(([unspendable]) => utxo.some(([utxoTxIn]) => txInEquals(utxoTxIn, unspendable))) ), - distinctUntilChanged((previous, current) => utxoEquals(previous, current)) + distinctUntilChanged((previous, current) => utxoEquals(previous, current)), + shareReplay(1) ) }; }; diff --git a/packages/wallet/test/services/UtxoTracker.test.ts b/packages/wallet/test/services/UtxoTracker.test.ts index 8745efb4758..fcb61327031 100644 --- a/packages/wallet/test/services/UtxoTracker.test.ts +++ b/packages/wallet/test/services/UtxoTracker.test.ts @@ -267,10 +267,8 @@ describe('createUtxoTracker', () => { ); expectObservable(utxoTracker.total$).toBe('-a--b---|', { a: utxo, b: utxo2 }); expectObservable(utxoTracker.unspendable$).toBe('-a--b---|', { a: [utxo[0]], b: [] }); - expectObservable(utxoTracker.available$).toBe('-a--b---|', { - a: utxo2, - b: utxo2 - }); + // utxo2 = utxo-unspendable + expectObservable(utxoTracker.available$).toBe('-a------|', { a: utxo2 }); }); }); });