APIs
Wallet API
Server
Extras
Rxjs

RXJS

WalletAPIServer uses a bit of rxjs (version 7) to handle data coming in from ledger live.
You should be familiar with it (if not, start here https://www.learnrxjs.io/#brand-new-to-rxjs (opens in a new tab)). In case you just need a refresher, you'll find below all the different rxjs operators and functions used in wallet-api-server.

map

https://rxjs.dev/api/operators/map (opens in a new tab)

observable

https://rxjs.dev/guide/observable (opens in a new tab)

BehaviorSubject

https://www.learnrxjs.io/learn-rxjs/subjects/behaviorsubject (opens in a new tab)

Requires an initial value and emits the current value to new subscribers

// RxJS v6+
import { BehaviorSubject } from "rxjs";
 
const subject = new BehaviorSubject(123);
 
// two new subscribers will get initial value => output: 123, 123
subject.subscribe(console.log);
subject.subscribe(console.log);
 
// two subscribers will get new value => output: 456, 456
subject.next(456);
 
// new subscriber will get latest value (456) => output: 456
subject.subscribe(console.log);
 
// all three subscribers will get new value => output: 789, 789, 789
subject.next(789);
 
// output: 123, 123, 456, 456, 456, 789, 789, 789

combineLatest

https://www.learnrxjs.io/learn-rxjs/operators/combination/combinelatest (opens in a new tab)

When any observable emits a value, emit the last emitted value from each.

let's look at this function

const allowedCurrencies$ = new BehaviorSubject([]);
 
combineLatest(
  [this.allCurrencies$, this.permissions.currencyIds$],
  matchCurrencies
).subscribe(allowedCurrencies$);

Here, allowedCurrencies emit first an empty array, then it emits a new value: anytime, this.allCurrencies$ or this.permissions.currencyIds$ changes Those two values are passed to a projection function (which simply finds the currencies we have defined here)

(opens in a new tab)

firstValueFrom

https://rxjs.dev/api/index/function/firstValueFrom (opens in a new tab)

Converts an observable to a promise by subscribing to the observable, and returning a promise that will resolve as soon as the first value arrives from the observable. The subscription will then be closed.

(opens in a new tab)