diff --git a/src/network/ergo/balance/common.ts b/src/network/ergo/balance/common.ts index 84b34a654..1ec56ffbc 100644 --- a/src/network/ergo/balance/common.ts +++ b/src/network/ergo/balance/common.ts @@ -3,6 +3,7 @@ import { AssetInfo } from '@ergolabs/ergo-sdk/build/main/entities/assetInfo'; import { combineLatest, debounceTime, + defaultIfEmpty, from, map, Observable, @@ -34,7 +35,7 @@ export const availableTokensData$: Observable<[bigint, AssetInfo][]> = utxos$ }), ), ), - ), + ).pipe(defaultIfEmpty([])), ), map((availableTokensData) => availableTokensData.filter(([, assetInfo]) => !!assetInfo), diff --git a/src/pages/Swap/Swap.tsx b/src/pages/Swap/Swap.tsx index 712c5f6ef..c188b0a0b 100644 --- a/src/pages/Swap/Swap.tsx +++ b/src/pages/Swap/Swap.tsx @@ -10,7 +10,7 @@ import { combineLatest, debounceTime, distinctUntilChanged, - first, + filter, map, Observable, of, @@ -61,7 +61,6 @@ const getSelectedPool = ( xId && yId ? getAmmPoolsByAssetPair(xId, yId).pipe( map((pools) => maxBy(pools, (p) => p.lp.amount)), - first(), ) : of(undefined); @@ -150,9 +149,11 @@ export const Swap = (): JSX.Element => { useSubscription( combineLatest([ form.controls.fromAsset.valueChangesWithSilent$.pipe( + filter(Boolean), distinctUntilChanged(), ), form.controls.toAsset.valueChangesWithSilent$.pipe( + filter(Boolean), distinctUntilChanged(), ), ]).pipe( diff --git a/src/services/new/core.ts b/src/services/new/core.ts index 0d8c0f5f5..a77ba61f4 100644 --- a/src/services/new/core.ts +++ b/src/services/new/core.ts @@ -3,6 +3,7 @@ import { AssetInfo } from '@ergolabs/ergo-sdk/build/main/entities/assetInfo'; import { combineLatest, distinctUntilChanged, + exhaustMap, filter, from, interval, @@ -85,7 +86,7 @@ export const appTick$ = walletState$.pipe( ); export const utxos$ = appTick$.pipe( - switchMap(() => from(ergo.get_utxos())), + exhaustMap(() => from(ergo.get_utxos())), map((bs) => bs?.map((b) => ergoBoxFromProxy(b))), map((data) => data ?? []), publishReplay(1), @@ -93,7 +94,7 @@ export const utxos$ = appTick$.pipe( ); export const nativeTokenBalance$ = appTick$.pipe( - switchMap(() => from(ergo.get_balance(ERG_TOKEN_NAME))), + exhaustMap(() => from(ergo.get_balance(ERG_TOKEN_NAME))), map((balance) => renderFractions(balance, ERG_DECIMALS)), publishReplay(1), refCount(),